<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Log;

class OperationRecord
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $response = $next($request);
        if($request->session()->get('isAdmin', false)){
            $map_Operator = [
                'id' => 0,
                'name' => '超级管理员'
            ];
        }else{
            $mod_User = $request->user();
            $map_Operator = [
                'id' => $mod_User->id,
                'name' => $mod_User->name
            ];
        }

        Log::info('[Operation record]',[
            'operator' => $map_Operator,
            'method' => $request->getMethod(),
            'uri' => $request->getRequestUri(),
            'params' => $request->all()
        ]);

        return $response;
    }
}
